#ifndef QUARK_H
#define QUARK_H

#include <sys/types.h>
#include <sys/uio.h>

#include "queue.h"

typedef enum {
  ALNUM_QUARK,	/* [a-zA-Z0-9]* */
  NONALNUM_QUARK,
  SENTINEL_QUARK,
} quark_syntax_e;

struct chunked_packet;

typedef struct quark {
  /* upper reference */
  struct chunked_packet *packet;

  /* syntax */
  quark_syntax_e syntax;
  /* content */
  struct iovec segment;

  TAILQ_ENTRY(quark) next_by_packet;
} quark_t;

quark_t *quark_sentinel();
int quark_cmp(const quark_t *, const quark_t *);

TAILQ_HEAD(quarkq,quark);

struct packet;
typedef struct chunked_packet {
  struct packet *packet;
  struct quarkq quarks;
  int n_quarks;
  TAILQ_ENTRY(chunked_packet) next_by_flow;
  TAILQ_ENTRY(chunked_packet) next_by_time;
} chunked_packet_t;

struct flowset;
typedef struct chunked_packets {
  TAILQ_HEAD(,chunked_packet) packets;
  struct flowset *set;
} chunked_packets_t;

chunked_packets_t *chunked_packets_tokenize(struct flowset *, int);

struct flow;
chunked_packet_t *chunked_packets_by_flow(chunked_packets_t *, struct flow *);

#endif /* QUARK_H */
